<?php

declare(strict_types=1);

/**
 * 首页服务
 * @author chenshubo
 */
namespace App\Controller\Shop;

use App\Model\CommodityModel\Classifyinfo;
use App\Model\PssModel\ShopHomeGroupConfig;
use App\Service\OrderService\OrderQueryService\QueryGoodsMicService;
use Hyperf\HttpServer\Contract\RequestInterface;
use App\Model\PssModel\AdvertiseManage;
use App\Model\PssModel\ShopRecommendBrand;
use App\Model\PssModel\ShopTopics;
use App\Model\PssModel\ShopGoodsGroupList;
use App\Model\PssModel\ShopSeckill;
use App\Service\Code\Normal;

class IndexController extends AbstractController
{
    /**
     * 获取广告位配置清单
     */
    public function getAdvertiseList()
    {
        return AdvertiseManage::instance()->getAdvertiseList();
    }
    
    /**
     * 获取广告位详情
     */
    public function getAdvertiseDetail(RequestInterface $request)
    {
        return AdvertiseManage::instance()->getAdvertiseDetail($request->getAttribute('param'));
    }
    
    //首页轮播图片
    public function getBannerList()
    {
        return ShopTopics::instance()->getBannerModuleList();
    }
    
    //推荐品牌
    public function getRecommandBrandList()
    {
        return ShopRecommendBrand::instance()->getRecommandBrandList();
    }
    
    //获取当前所有配置的（专题馆数据和秒杀数据）
    public function getAllShowTopicsList(RequestInterface $request)
    {
        $resTopicsList  = ShopTopics::instance()->getAllShowTopicsList();
        $resSeckillList = ShopSeckill::instance()->getGoodsSeckillIndexInfo($request->getAttribute('param'));
        return Normal::returnCode(Normal::SUC,"获取成功",[
            'topics'    => $resTopicsList['data'],
            'seckill'   => $resSeckillList['data']
        ]);
    }
    
    //获取商品组页面数据详情接口
    public function getGoodsGroupPageList(RequestInterface $request)
    {
        return ShopGoodsGroupList::instance()->getGoodsGroupPageList($request->getAttribute('param'));
    }
    
    //获取秒杀列表时间排序
    public function getSeckillList()
    {
        return ShopSeckill::instance()->getSeckillList();
    }
    
    //获取当前秒杀活动商品
    public function getSeckillGoodsList(RequestInterface $request)
    {
        return ShopSeckill::instance()->getSeckillGoodsListBySeckillId($request->getAttribute('param'));
    }
    
    //分类
    public function getClassList()
    {
        return Classifyinfo::instance()->getClassTreeFromMicoServicePriotity();
    }
    
    //商品数据
    public function getGoodsList(RequestInterface $request)
    {
        return QueryGoodsMicService::instance()->getShopIndexGoodsPageList($request->getAttribute('param'));
    }
    
    //查询品牌和分类
    public function getSearchClassAndBrands(RequestInterface $request)
    {
        return QueryGoodsMicService::instance()->getSearchClassAndBrands($request->getAttribute('param'));
    }
    
    //商品详情
    public function getGoodsDetail(RequestInterface $request)
    {
        return QueryGoodsMicService::instance()->getShopGoodsDetail($request->getAttribute('param'));
    }
    
    //计算价格
    public function getGoodsPrice(RequestInterface $request)
    {
        return QueryGoodsMicService::instance()->getGoodsPrice($request->getAttribute('param'));
    }
    
    /**
     * 立即购买接口
     */
    public function placeOrder(RequestInterface $request)
    {
        return QueryGoodsMicService::instance()->placeOrder($request->getAttribute('param'));
    }
    
    /**
     * 加入购物车
     */
    public function addGoodsCart(RequestInterface $request)
    {
        return QueryGoodsMicService::instance()->addGoodsCart($request->getAttribute('param'));
    }

    /**
     * 获取导航栏
     */
    public function getShopHomeGroupConfig(RequestInterface $request)
    {
        return Normal::returnCode(Normal::SUC,'获取成功',ShopHomeGroupConfig::instance()->getGroupConfigs());
    }

    /**
     * 获取导航栏
     */
    public function getShopHomeGroupConfigDetail(RequestInterface $request)
    {
        $body  = $request->getAttribute('param')['body'];
        $binfo  = $request->getAttribute('param')['binfo'];
        $data  = ShopHomeGroupConfig::instance()->getGroupConfigsDetail([
            'body'=>$body,
            'binfo'=>$binfo
        ]);
        return Normal::returnCode(Normal::SUC,'获取成功',$data);
    }
}
